var myCirclePlayer;
var currItemNumber;
var sermonList = [
	"../AUDIO/2014/SUNDAY%20SCHOOL/09142014sundayschool.mp3",
	"../AUDIO/2014/AM%20SERVICE/09142014amservice.mp3",
	"../AUDIO/2014/AM%20SERVICE/09142014pmservice.mp3",
	"../AUDIO/2014/AM%20SERVICE/09152014pmservice1.mp3",
	"../AUDIO/2014/AM%20SERVICE/09152014pmservice2.mp3",
	"../AUDIO/2014/AM%20SERVICE/09162014pmservice1.mp3",
	"../AUDIO/2014/AM%20SERVICE/09162014pmservice2.mp3",
	"../AUDIO/2014/AM%20SERVICE/09172014amservice1.mp3",
	"../AUDIO/2014/AM%20SERVICE/09172014amservice2.mp3",
	"../AUDIO/2014/AM%20SERVICE/09172014amservice3.mp3",
	"../AUDIO/2014/AM%20SERVICE/09172014pmservice1.mp3",
	"../AUDIO/2014/AM%20SERVICE/09172014pmservice2.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Holdsworth%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%202.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%203.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%204.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%205.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%206.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%207.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%208.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%209.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2010.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2011.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2012.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2013.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2014.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2015.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2016.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2017.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2018.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2019.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2020.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2021.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2022.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Living%20Proof%2023.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%202.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%203.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%204.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%205.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%206.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Mullins%207.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%202.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%203.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%204.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%205.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%206.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%207.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%208.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Smiths%209.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Stanfords%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Thrift%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Tribur-McCaffety%201.mp3",
	"../AUDIO/2014/CAMPMEETING%202014/Triburs%201.mp3"
];

function selectItem(item) {
    if (0 <= currItemNumber && currItemNumber < sermonList.length) {
    	var currItem = document.getElementById("player-item-" + currItemNumber.toString());
        removeClass(currItem, 'bold');
        removeClass(currItem, 'colorPrimary-5');
        addClass(currItem, 'colorSecondary-a-2');
    }
    addClass(item, 'bold');
    addClass(item, 'colorPrimary-5');
    removeClass(item, 'colorSecondary-a-2');
    currItemNumber = parseInt(item.id.substr(item.id.lastIndexOf("-") + 1));
    myCirclePlayer.setMedia({
    	mp3: sermonList[currItemNumber]
    });
}

function playItem(item) {
    selectItem(item);
	myCirclePlayer.play();
}

function playNextItem() {
    var nextItemNumber = currItemNumber + 1;
    if (nextItemNumber < sermonList.length) {
        playItem(document.getElementById("player-item-" + nextItemNumber.toString()));
    }
}

$(document).ready(function(){
	myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
	{
	}, {
		supplied: "mp3",
		cssSelectorAncestor: "#cp_container_1",
		swfPath: "../Content/Javascript/jplayer/Jplayer.swf",
		wmode: "window",
		keyEnabled: true
	});

	$("#jquery_jplayer_1").bind($.jPlayer.event.ended, function (event) {
		if (currItemNumber < 11) {
        	playNextItem();
    	}
    });

	for(var i = 0; i < sermonList.length; ++i){
		addClass(document.getElementById("player-item-" + i.toString()), 'colorSecondary-a-2');
	}

	selectItem(document.getElementById("player-item-0"));
});
